package com.aiyige.page.publish.publishresult;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.aiyige.R;
import com.aiyige.arouter.config.ARouterConfig;
import com.aiyige.page.my.merchandisemanagement.model.TabItem;
import com.alibaba.android.arouter.launcher.ARouter;

import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class SubmitReviewDialog {
    Dialog dialog;
    Integer targetTab = null;
    Context context;

    public SubmitReviewDialog(Context context) {
        this.context = context;
        dialog = new Dialog(context, R.style.loading_dialog_style);
        dialog.setContentView(R.layout.submit_review_dialog);
        dialog.findViewById(R.id.gotItBtn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (targetTab != null) {
                    ARouter.getInstance()
                            .build(ARouterConfig.MerchandiseManagementPage)
                            .withInt("targetTab", targetTab)
                            .navigation();
                }
                dialog.dismiss();
            }
        });
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(true);
    }

    public Integer getTargetTab() {
        return targetTab;
    }

    public void setTargetTab(Integer targetTab) {
        this.targetTab = targetTab;
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public void showDialog() {
        if (context != null && !((Activity) context).isFinishing()) {
            dialog.show();
        }
    }

    public static final class Builder {
        SubmitReviewDialog submitReviewDialog;

        private Builder() {
        }

        public Builder with(Context context) {
            submitReviewDialog = new SubmitReviewDialog(context);
            return this;
        }

        public Builder targetTab(Integer targetTab) {
            submitReviewDialog.setTargetTab(targetTab);
            return this;
        }

        public SubmitReviewDialog build() {
            return submitReviewDialog;
        }

        public SubmitReviewDialog show() {
            submitReviewDialog.showDialog();
            return submitReviewDialog;
        }
    }


}
